package cn.edu.sptc.chensiyi.hellospring.runner;

import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@Component
public class MyApplicationRunner implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args)throws  Exception{
        log.info("应用冷启动完成报时，当前时刻为："+getDateTimeByLocalDateTime());
    }

//    public  static String getDateTimeByCurrentMillis(){
//        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS EEE");
//        return simpleDateFormat.format(System.currentTimeMillis());
//    }

    public  static String getDateTimeByLocalDateTime(){
        DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS EEE");
        return dateTimeFormatter.format(LocalDateTime.now());
    }
}
